package com.rr.learningdemo.rabbitmq.thread;

import io.lettuce.core.RedisCommandTimeoutException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author zhuangcanrun
 * @Date 2021/06/22/10:22
 * @description
 **/

@Component
public class RedisListenerThreadForList extends Thread{

    @Autowired
    private RedisTemplate redisTemplate;

    public void consumer() {
        System.out.println("brpop---");

        Object o;
        try {
            o = redisTemplate.opsForList().rightPop("list", 100L, TimeUnit.DAYS);
        } catch (Exception e) {
            System.out.println("异常捕获，无事发生");
            o = null;
        }

        System.out.println("消费" + o);

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        while (true) {
            consumer();
        }
    }
}
